<script type="text/javascript" language="javascript">
    (function($) {
        /*whatever jQuery stuff*/
        $(function(){					
            $("#Form").validate({
				ignore: "",
                rules: {
					playlist_name: "required",
					playlist_alias: "required"
                },
                showErrors: function(errorMap, errorList){
                    var messages='';
                    for (var i = 0; i < errorList.length; i++) {					
                        messages += '- '+errorList[i].message+'\n';
                    }
                    if(messages) alert("<?php echo lang('requirement');?>: \n"+"¯¯¯¯¯¯¯¯¯¯ \n"+ messages);
                    //this.defaultShowErrors();
                } ,
                submitHandler: function(e){
					$('.ajax-loading',e).css('visibility','visible');
					if(queueSize > 0){
						$('#file_upload').uploadifyUpload();
					} else { success_file = true; }				
					var interval = setInterval(function() {
					    if (success_file) {
					        clearInterval(interval);
							//Send Form
					        document.forms["Form"].submit();
					    }
					}, 100);
                },
                onfocusout: false,
                onkeyup: false,
				onclick: false,					
                messages: {
					playlist_alias: "<?php echo lang('playlist_alias');?>",
					playlist_name: "<?php echo lang('playlist_name');?>"			
                }
            });	
		
            /*Images Upload*/
            var queueSize = 0;		
            var imgname= new Array();
			var success_file = false;					
            $('#file_upload').uploadify({
                'uploader'  : '<?php echo base_url();?>uploadify.swf',				
                'script'    : '<?php echo base_url();?>uploadify.php',
                'cancelImg' : '<?php echo js_asset_url("uploadify/cancel.png"); ?>',
                'folder'    : "<?php echo substr($this->temp_folder,0,-1);?>",
                'fileExt'   : '*.jpg;*.JPG;*.gif;*.GIF;*.png;*.PNG',
                'fileDesc'  : 'All Files',
				'scriptAccess' : 'always',			
                'auto'      : false,
                'multi'     : false,
                'onComplete' : function(event, ID, fileObj, response, data){
                    imgname.push(response);
                },
                'onAllComplete' : function(event,data) {
					$('<input>').attr({
					    type: 'hidden',
					    id: 'uploadify_store',
					    name: 'uploadify_store',
						value: imgname
					}).appendTo('Form');
					//document.forms["Form"].submit();					
					success_file=true;
                },
                'onSelectOnce' : function (event,data) {
                    queueSize = data.fileCount;
                },
                'onCancel' : function (event,ID,fileObj,data) {
                    queueSize = data.fileCount;
                }						
            });	

			//ColorBox Iframe
			$('.search_tools').colorbox({iframe:true, innerWidth:300, innerHeight:600, right:0, opacity:0.4});
        });
    })(jQuery);	
/*Add/Remove List*/
function addRemoveList(unique,id,name)
{
	if(id == undefined && name == undefined){ //remove List
		var parentElement = $(unique).closest('ul');
		$(unique).parent().remove();
		if($('li:not(:hidden)',parentElement).length < 1){
			parentElement.find('.first').show();
		}	
	} else { //add List
		var parentElement = $('ul#media_id');
		var value = (unique == "song_id" ? ""+id+"":"video_"+id);
		parentElement.find('.first').hide();
		if($('input[value="'+value+'"]',parentElement).length == 0){
			parentElement.prepend('<li><input type="checkbox" name="default_media_id[]" value="'+value+'" checked="checked"/>&nbsp;'+id+' - '+name+' <a href="javascript:void(0)" class="tools minus" onclick="javascript:addRemoveList(this);"></a><input type="hidden" name="media_id[]" value="'+value+'" \/><\/li>');
		}		
	}
}	
</script>
<div class="wrap">
 	<div id="icon-index" class="icon32"><br /></div><h2><?php echo ucwords(str_replace('_',' ',$this->uri->segment(1)));?> &raquo; <?php echo ucwords(str_replace('_',' ',$this->uri->segment(2)));?> &raquo; <?php echo lang($this->uri->segment(3));?></h2>
</div>
<div id="wpbody-content">
    <div class="metabox-holder" id="dashboard-widgets">
		<div class="tablenav top">
			<div class="alignleft"><input type="button" value="<?php echo lang('button_back');?>" class="button-primary" onclick="javascript:history.go(-1);"/></div>
		</div>	
            <div class="inside">			
				<form id="Form" method="post" action="" name="Form">
					<table border="0" cellspacing="0" cellpadding="0" class="form-table">
						<tbody>	
						<tr>
							<th scope="row"><?php echo lang('is_publish');?></th>
							<td>
								<input type="radio" name="is_publish" value="1" checked="checked"/> <?php echo lang('yes');?>
								<input type="radio" name="is_publish" value="0" /> <?php echo lang('no');?>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('playlist_hilight');?></th>
							<td>
								<input type="radio" name="is_hilight" value="1" /> <?php echo lang('yes');?>
								<input type="radio" name="is_hilight" value="0" checked="checked"/> <?php echo lang('no');?>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('playlist_recommend');?></th>
							<td>
								<input type="radio" name="is_recommend" value="1" /> <?php echo lang('yes');?>
								<input type="radio" name="is_recommend" value="0" checked="checked"/> <?php echo lang('no');?>
							</td>
						</tr>												
						<tr>
							<th scope="row"><?php echo lang('playlist_alias');?></th>
							<td><input type="text" name="playlist_alias" id="playlist_alias" class="medium-text" /></td>
						</tr>																							
						<tr>
							<th scope="row"><?php echo lang('playlist_name');?></th>
							<td><input type="text" name="playlist_name" id="playlist_name" class="regular-text" /></td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('playlist_brief');?></th>
							<td><textarea name="playlist_brief" id="playlist_brief" rows="5" class="regular-text"></textarea></td>
						</tr>
						<tr>
							<th scope="row">
								<?php echo lang('song_relate');?> <a href="<?php echo base_url().'song/playlist_management/search_song';?>" class="tools plus search_tools"></a><br />
								<?php echo lang('video_relate');?> <a href="<?php echo base_url().'song/playlist_management/search_video';?>" class="tools plus search_tools"></a>
							</th>
							<td class="describe">
								<ul id="media_id" class="listItems">
									<li class="first"><?php echo lang('no_media_relate');?></li>
								</ul>
							</td>
						</tr>		
						<tr>
							<th scope="row"><?php echo lang('playlist_image');?></th>
							<td><input type="file" name="file_upload" id="file_upload"/></td>
						</tr>																						
						<tr>
							<th scope="row">&nbsp;</th>
							<td><p class="submit"><input type="submit" value="<?php echo lang('button_add');?>" class="button-primary" />&nbsp;<img alt="" class="ajax-loading" src="<?php echo css_asset_url('images/wpspin_light.gif'); ?>" /></p></td>
						</tr>								
						</tbody>
					</table>
					<div class="tablenav bottom"></div>
				</form>
            </div><!-- wpbody inside -->
    </div><!-- wpcontent -->
</div><!-- wpbody-content -->